package Window;

import Window.DetailWidget.MenuButton;

import java.awt.CardLayout;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JPanel;

import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.BoxLayout;


public class MainWindow extends JFrame {

	public static final int WIDTH = 1500;
	public static final int HEIGHT = 844;
	public static final String TITLE = "Java五子棋";

	public static CardLayout cardLayout = new CardLayout();				//多界面布局

	public static JPanel mainPanel = new JPanel();						//总窗口panel
	private JPanel contentPane = new JPanel();							//主界面
	private OnlinebattlePanel onlinebattlePanel = new OnlinebattlePanel();//登录入口
	private AdminRegister adminRegister = new AdminRegister();			//注册界面
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainWindow frame = new MainWindow();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	public MainWindow() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle(TITLE);

		setSize(WIDTH,HEIGHT);
		setLocationRelativeTo(null);
		contentPane.setSize(WIDTH, HEIGHT);
		contentPane.setLayout(null);

		mainPanel.setLayout(cardLayout);
		mainPanel.add(contentPane);

		mainPanel.add(contentPane, "主界面");
		mainPanel.add(onlinebattlePanel,"登录入口");
		mainPanel.add(adminRegister,"注册界面");
		setContentPane(mainPanel);

		//设置背景图片
		JLabel lblNewLabel = new JLabel();
		lblNewLabel.setSize(WIDTH, HEIGHT);
		ImageIcon imageIcon = new ImageIcon(this.getClass().getResource("image/bg_main.png"));
		imageIcon.setImage(imageIcon.getImage().getScaledInstance(WIDTH, HEIGHT, Image.SCALE_DEFAULT));//设置图片大小适应label
		lblNewLabel.setIcon(imageIcon);

		JPanel panelMenu = new JPanel();
		panelMenu.setOpaque(false);
		panelMenu.setBounds((int)(WIDTH * 0.7), (int)(HEIGHT / 20), 302, HEIGHT - HEIGHT / 20 * 3);
		contentPane.add(panelMenu);
		panelMenu.setLayout(new BoxLayout(panelMenu, BoxLayout.Y_AXIS));

		JButton buttonNet = new MenuButton();
		buttonNet.setIcon(new ImageIcon(MainWindow.class.getResource("/Window/image/register_enter.png")));
		panelMenu.add(buttonNet);
		buttonNet.addMouseListener(new MouseListener() {

			@Override
			public void mouseReleased(MouseEvent e) {
				buttonNet.setIcon(new ImageIcon(MainWindow.class.getResource("/Window/image/register_enter.png")));
				cardLayout.show(mainPanel, "登录入口");
			}

			@Override
			public void mousePressed(MouseEvent e) {
				buttonNet.setIcon(new ImageIcon(MainWindow.class.getResource("/Window/image/register_enter.png")));
			}

			@Override
			public void mouseExited(MouseEvent e) {
				buttonNet.setIcon(new ImageIcon(MainWindow.class.getResource("/Window/image/register_enter.png")));
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				buttonNet.setIcon(new ImageIcon(MainWindow.class.getResource("/Window/image/register_enter.png")));
			}

			@Override
			public void mouseClicked(MouseEvent e) {

			}
		});
		JButton buttonExit = new MenuButton();
		buttonExit.setIcon(new ImageIcon(MainWindow.class.getResource("/Window/image/exit_system.png")));
		panelMenu.add(buttonExit);
		buttonExit.addMouseListener(new MouseListener() {

			@Override
			public void mouseReleased(MouseEvent e) {
				buttonExit.setIcon(new ImageIcon(MainWindow.class.getResource("/Window/image/exit_system.png")));
			}

			@Override
			public void mousePressed(MouseEvent e) {
				buttonExit.setIcon(new ImageIcon(MainWindow.class.getResource("/Window/image/exit_system.png")));
				dispose();
			}

			@Override
			public void mouseExited(MouseEvent e) {
				buttonExit.setIcon(new ImageIcon(MainWindow.class.getResource("/Window/image/exit_system.png")));
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				buttonExit.setIcon(new ImageIcon(MainWindow.class.getResource("/Window/image/exit_system.png")));
			}

			@Override
			public void mouseClicked(MouseEvent e) {
			}
		});

		contentPane.add(lblNewLabel);
	}
}
